<div ng-if="service.EnvironmentVariables" id="service-env-variables">
  <rd-widget>
    <rd-widget-header icon="fa-tasks" title-text="环境变量">
      <div class="nopadding" authorization="DockerServiceUpdate">
        <a class="btn btn-default btn-sm pull-right" ng-click="isUpdating ||addEnvironmentVariable(service)" ng-disabled="isUpdating">
          <i class="fa fa-plus-circle" aria-hidden="true"></i> 环境变量
        </a>
      </div>
    </rd-widget-header>
    <rd-widget-body ng-if="service.EnvironmentVariables.length === 0">
      <p>该服务中没有环境变量</p>
    </rd-widget-body>
    <rd-widget-body ng-if="service.EnvironmentVariables.length > 0" classes="no-padding">
      <table class="table">
        <thead>
          <tr>
            <th>名称</th>
            <th>值</th>
          </tr>
        </thead>
        <tbody>
          <tr ng-repeat="var in service.EnvironmentVariables | orderBy: 'originalKey'">
            <td>
              <div class="input-group input-group-sm">
                <span class="input-group-addon fit-text-size">名称</span>
                <input type="text" class="form-control" ng-model="var.key" ng-disabled="var.added || isUpdating" placeholder="例如：FOO" />
              </div>
            </td>
            <td>
              <div class="input-group input-group-sm">
                <span class="input-group-addon fit-text-size">值</span>
                <input
                  type="text"
                  class="form-control"
                  ng-model="var.value"
                  ng-change="updateEnvironmentVariable(service, var)"
                  placeholder="例如：bar"
                  ng-disabled="isUpdating"
                  disable-authorization="DockerServiceUpdate"
                />
                <span class="input-group-btn" authorization="DockerServiceUpdate">
                  <button class="btn btn-sm btn-danger" type="button" ng-click="removeEnvironmentVariable(service, var)" ng-disabled="isUpdating">
                    <i class="fa fa-trash" aria-hidden="true"></i>
                  </button>
                </span>
              </div>
            </td>
          </tr>
        </tbody>
      </table>
    </rd-widget-body>
    <rd-widget-footer authorization="DockerServiceUpdate">
      <div class="btn-toolbar" role="toolbar">
        <div class="btn-group" role="group">
          <button type="button" class="btn btn-primary btn-sm" ng-disabled="!hasChanges(service, ['EnvironmentVariables'])" ng-click="updateService(service)">应用更改</button>
          <button type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
            <span class="caret"></span>
          </button>
          <ul class="dropdown-menu">
            <li><a ng-click="cancelChanges(service, ['EnvironmentVariables'])">重置更改</a></li>
            <li><a ng-click="cancelChanges(service)">重置所有更改</a></li>
          </ul>
        </div>
      </div>
    </rd-widget-footer>
  </rd-widget>
</div>
